package com.mytinyRPC.register;/*
package com.mytinyrpc.register;


import java.io.*;
import java.util.*;
*/
/***
 * @Author HP
 * @Description //远程注册表，共享序列化文件实现 测试类//
 **//*

public class RemoteMapRegister {

    private Map<String, List<URL>> registerMap = new HashMap<String,List<URL>>(1024);
    public final String path = "/tmp.txt";

    public Map<String, List<URL>> getRegisterMap() {
        return registerMap;
    }

    public void setRegisterMap(Map<String, List<URL>> registerMap) {
        this.registerMap = registerMap;
    }

    public String getPath() {
        return path;
    }

    public void registerService(String interfaceName, URL host) {
        if(registerMap.containsKey(interfaceName)){
            List<URL> list = registerMap.get(interfaceName);
            list.add(host);
        }else {
            List<URL> list = new LinkedList<URL>();
            list.add(host);
            registerMap.put(interfaceName,list);
        }
        try {
            saveFile(path,registerMap);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public List<URL> getURL(String interfaceName) {
        try {
            registerMap = (Map<String, List<URL>>) readFile(path);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return registerMap.get(interfaceName);
    }


//文件方式存储
    */
/**
     * 写入文件
     * @param path
     * @param object
     * @throws IOException
     *//*

    private static void saveFile(String path,Object object) throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
        ObjectOutputStream objectOutputStream =new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(object);
    }

    */
/**
     * 从文件中读取
     * @param path
     * @return
     * @throws IOException
     * @throws ClassNotFoundException
     *//*

    private static Object readFile(String path) throws IOException, ClassNotFoundException {
        FileInputStream fileInputStream = new FileInputStream(new File(path));
        ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
        return inputStream.readObject();
    }



}
*/
